package com.WaVel.controller.admin;

import com.Emplyment.result.Result;
import com.WaVel.service.InterviewDiscussionService;
import lombok.extern.slf4j.Slf4j;
import org.apache.ibatis.annotations.Delete;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/interviewForum")
@Slf4j
public class InterviewDiscussionController {

    @Autowired
    private InterviewDiscussionService interviewDiscussionService;

    /**
     * 获取面经信息
     */
    @GetMapping("/getInterviewArticle")
    public Result getInterviewForum(@RequestParam("category") String category) {
        log.info("获取面经信息:{}",category);
        //获取文章信息
        return Result.success(interviewDiscussionService.getInterviewArticles(category));
    }

    @DeleteMapping("/deleteInterviewComment/{id}")
    public Result deleteInterviewComment(@PathVariable("id") int id) {
        //删除文章评论
        log.info("删除面经评论:{}",id);
        interviewDiscussionService.deleteInterviewComment(id);
        return Result.success();
    }

    @DeleteMapping("/deleteInterviewArticle/{id}")
    @Transactional
    public Result deleteInterviewArticle(@PathVariable("id") int id) {
        //删除文章
        log.info("删除面经文章:{}",id);
        interviewDiscussionService.deleteInterviewArticle(id);
        return Result.success();
    }

}
